const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;

void async function () {
    let n = Number(await readline());
    let range = [];
    for (let i = 0; i < n; i++) {
        let line = await readline();
        let list = line.split(' ').map(Number);
        range.push( [list[0], list[1]] );
    }

    // 按照左端点排序，若左端点相同，则按右端点排序
    range.sort((a, b) => a[0] - b[0] || a[1] - b[1]);

    let count = 0;
    // 毕竟题目中区间范围>=0
    let maxRight = -1;
    let maxLeft = Number.MAX_VALUE
    for (let i = 0; i < n; i++) {
        let [lu, ru] = range[i];
        // 当前区间右端点 ru 大于等于之前区间的右端点的最大值时，满足条件
        if (ru >= maxRight && lu <= maxLeft) {
            count++;
        }
        maxRight = Math.max(maxRight, ru);
        maxLeft = Math.min(maxLeft, lu);
    }

    console.log(count);
}();
